{% extends 'CHOMPSGIBundle:Incidentes:base.html.twig' %}

{% block subtitle %}Editar{% endblock %}

{% set active_page = "incidentes_editar" %}
{% block content %}

	<script>
		$(document).ready(function(){
			$('#chomp_sgibundle_incidente_grupoSoporte').attr("onchange", "comprobarGrupoSoporte()");
			comprobarGrupoSoporte();
			$('#chomp_sgibundle_incidente_update_data').hide();
			$('#chomp_sgibundle_incidente_empresa').change(function(){
				$('#chomp_sgibundle_incidente_update_data').click();
			});
			$(document).keypress(function(e) {
				if(e.which == 13) {
					$('#chomp_sgibundle_incidente_update_data').click();
				}
			});
		});
		$('#chomp_sgibundle_incidente_grupoSoporte').change(comprobarGrupoSoporte());
		
		function comprobarGrupoSoporte(){

		var options = "";
		{% for grupoSoporte in gruposSopote %}
			if( {{ grupoSoporte.id }} == $('#chomp_sgibundle_incidente_grupoSoporte').val()){
								
				{% for usuario in grupoSoporte.usuarios %}
					options = options + "<option value='{{ usuario.id }}'>{{ usuario.login }}</option>"
				{% endfor %}
				
			}
		{% endfor %}

		$('#chomp_sgibundle_incidente_responsableSoporte').html(options);
			
		}
	</script>
	<script>
		$(document).ready(function() {
			
			// Get the ul that holds the collection of tags
			var collectionHolder = $('#chomp_sgibundle_incidente_comentarios');

			// setup an "add a tag" link
			var $addComentarioLink = $('<a href="#" class="add_comentario_link">Agregar Comentario</a>');
			
			var $newLinkLi = $('<div></div>').append($addComentarioLink);
			
			// add the "add a tag" anchor and li to the tags ul
			collectionHolder.append($newLinkLi);

			// count the current form inputs we have (e.g. 2), use that as the new
			// index when inserting a new item (e.g. 2)
			collectionHolder.data('index', collectionHolder.find(':input').length);

			$addComentarioLink.on('click', function(e) {
				// prevent the link from creating a "#" on the URL
				e.preventDefault();

				// add a new tag form (see next code block)
				addComentarioForm(collectionHolder, $newLinkLi);
			});
		});
		
		function addComentarioForm(collectionHolder, $newLinkLi) {
			// Get the data-prototype explained earlier
			var prototype = collectionHolder.data('prototype');

			// get the new index
			var index = collectionHolder.data('index');

			// Replace '__name__' in the prototype's HTML to
			// instead be a number based on how many items we have
			var newForm1 = prototype.replace(/__name__label__/g, index);
			var newForm = newForm1.replace(/__name__/g, index);
			
			// increase the index with one for the next item
			collectionHolder.data('index', index + 1);

			// Display the form in the page in an li, before the "Add a tag" link li
			var $newFormLi = $('<div class="row"></div>').append(newForm);

			$newLinkLi.before($newFormLi);
		}
	</script>
	
	<h1>Edicion de incidente</h1>

	{{ form_start(form, {attr: {novalidate: 'novalidate'}}) }}


	<form action="#" method="post" {{ form_enctype(form) }}>
		<div class="row-fluid">
			<div class="span10" style="width: 100%;">
				<div class="span12"> 
					<div class="incidente-container">
						<div class="container">

							<div class="row-fluid">
								{{ form_errors(form) }}
							</div>
							<div class="row-fluid">
								<div class="form_row2">
									<label>
										Fecha de creación:
									</label>
									<div class="outputText">
										{{incidente.getFechaCreacion().format('d-m-Y') | default("") }}
									</div>
								</div>

								<div class="form_row2">
									<label>
										Creado por:
									</label>
									<div class="outputText">
										{{incidente.getCreador()}} 
									</div>
								</div>
							</div>
							<div class="row-fluid">
								<div class="form_row2">
									{{ form_label(form.estado) }}
									{{ form_widget(form.estado) }}
								</div>

								<div class="form_row2">
									{{ form_label(form.prioridad) }}
									{{ form_widget(form.prioridad) }}
								</div>
							</div>
							<div class="row-fluid">
								<div class="form_row2">
									{{ form_label(form.fechaCierreAutomatico) }}
									{{ form_widget(form.fechaCierreAutomatico) }}
								</div>

								<div class="form_row2">
									<!--
									<label>
										Fecha limite
									</label>
									<div class="outputText">
									</div>
									-->

								</div>
							</div>
							<div class="row-fluid">
						{% spaceless %}
							{% if 'EDITAR_INCIDENTE_GRUPOSOPORTE' in permisos or 'EDITAR_INCIDENTE_ALL' in permisos %}
								<div class="form_row2">
									{{ form_label(form.grupoSoporte) }}
									{{ form_widget(form.grupoSoporte) }}
								</div>
							{% endif %}
						{% endspaceless %}
						{% spaceless %}
							{% if 'EDITAR_INCIDENTE_RESPONSABLESOPORTE' in permisos or 'EDITAR_INCIDENTE_ALL' in permisos %}
								<div class="form_row2">
									{{ form_label(form.responsableSoporte) }}
									{{ form_widget(form.responsableSoporte) }}
								</div>
							{% endif %}
						{% endspaceless %}

							</div>
							<div class="row-fluid">
								<div class="form_row2">
									{{ form_label(form.empresa) }}
									{{ form_widget(form.empresa) }}
								</div>
								<div class="form_row2">
									{{ form_label(form.responsableCliente) }}
									{{ form_widget(form.responsableCliente) }}
								</div>
							</div>
						{% spaceless %}
							{% if 'EDITAR_INCIDENTE_CUENTAANALITICA' in permisos or 'EDITAR_INCIDENTE_ALL' in permisos %}
							<div class="row-fluid">
								<div class="form_row2">
									{{ form_label(form.cuentaAnalitica) }}
									{{ form_widget(form.cuentaAnalitica) }}
								</div>
							</div>
							{% endif %}
						{% endspaceless %}
						</div>

						<div class="container" style="margin-top:30px;">
							<h4 style="padding-left: 20px;">Detalle Incidente</h4>
						
							<div class="row-fluid">
								<div class="form_row3">
									{{ form_label(form.titulo) }}
									{{ form_widget(form.titulo) }}
									{{ form_errors(form.titulo) }}
								</div>
							</div>
							<div class="row-fluid">
								<div class="form_row3">
									{{ form_label(form.descripcion) }}
									{{ form_widget(form.descripcion) }}
									{{ form_errors(form.descripcion) }}
								</div>
							</div>
							<div class="row-fluid">
								<div class="form_row3">
									<label>
										Adjuntos
									</label>
									{{ form_widget(form.file) }}
								</div>
							</div>
							  
						</div>

						<div style="clear:both; margin:10px 0 ; float:right">
							
							{{ form_widget(form.save) }}

							<a class="btn" href="{{ path('incidentes_listar') }}">
								Cancelar
							</a>	  
							
							 {{ form_end(form) }}		
						</div>	
					</div>
				</div>
			</div>
		</div>
	</form>

{% endblock %}
